package com.yyfax.ph.personal.authority.changepassword;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Title: ChangePasswordModel Description: Company: YYLending(YouJingPuHui)
 *
 * @author XiongYuFeng
 *         date 2016年5月10日 下午4:09:33
 */
public class ChangePasswordModel extends Model {
	private static final String TAG = ChangePasswordModel.class.getSimpleName();

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.register(token, (ChangePwdParams) params);
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		ChangePasswordModel.ChangePwdResult registerResult = cast(obj);
		EventAgent.post(registerResult);
	}

	private interface Service {
		@POST("sys/user/modifyPwd")
		Observable<ChangePwdResult> register(@Header("token") String token, @Body ChangePwdParams params);
	}

	public static class ChangePwdParams {
		/***
		 *
		 新密码（RSA加密）
		 */
		public String newPassword;
		/***
		 *密码（RSA加密）
		 */
		public String password;
		/***
		 * 极光id
		 */
		String regId = YJPH.getInstance().getPreferenceManager().getJPushRegId();
	}

	public static class ChangePwdResult extends BaseResultEntity<String> {
	}
}
